<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="width=400;" />

    <script type="text/javascript" src="http://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'รายชื่อตำบล');
        data.addColumn('number', 'เลือก');
        data.addColumn('number', 'ไม่เลือก');
        data.addColumn('number', 'ทั้งหมด');
        data.addRows(<?php echo sizeof($result)+1;?>);


      <?php
      $i = 0;
      $j = 1;

      foreach($result as $val){
       $tambonName = $val['tam_name'];
       $personSelected = $selected[$i]['count_person'];
       $personNotSelected = $notselected[$i]['count_person'];
       $allSelected = $val['count_person'];
      ?>
        data.setValue(<?php echo $j;?>, 0, '<?php echo $tambonName;?>');
        data.setValue(<?php echo $j;?>, 1, <?php echo $personSelected;?>);
        data.setValue(<?php echo $j;?>, 2, <?php echo $personNotSelected;?>);
        data.setValue(<?php echo $j;?>, 3, <?php echo $allSelected;?>);
      <?php
        $i++;
        $j++;
      }
      ?>

        var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
        chart.draw(data, {width: 400, height: 400, title: 'สรุปผลการสำรวจข้อมูล',
                          hAxis: {title: 'รายชื่อตำบล', titleTextStyle: {color: 'red'}}
                         });
      }
    </script>
  </head>

  <body>
    <div id="chart_div"></div>
  </body>
</html>